import { defaultWagmiConfig } from '@web3modal/wagmi/react/config'
import { defineChain } from "viem";
import { cookieStorage, createStorage , http } from 'wagmi'
import { mainnet } from 'wagmi/chains'

// Get projectId at https://cloud.walletconnect.com
export const projectId = process.env.NEXT_PUBLIC_PROJECT_ID

if (!projectId) throw new Error('Project ID is not defined')

const metadata = {
  name: 'Web3Modal',
  description: 'Web3Modal Example',
  url: 'https://web3modal.com', // origin must match your domain & subdomain
  icons: ['https://avatars.githubusercontent.com/u/37784886']
}

export const privateChain = defineChain({
  id: parseInt(process.env.NEXT_PUBLIC_PRIVATE_CHAIN_ID as string),
  name: "RedaChain",
  nativeCurrency: { name: "rdETH", symbol: "rdETH", decimals: 18 },
  rpcUrls: {
    default: {
      http: [process.env.NEXT_PUBLIC_RPC as string],
    },
  },
});
 
export const config = defaultWagmiConfig({
  chains: [privateChain],
  projectId,
  metadata,
  ssr: true,
  storage: createStorage({
    storage: cookieStorage
  }),
  transports: {
    [privateChain.id]: http(),
  },
//   ...wagmiOptions // Optional - Override createConfig parameters
})